﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Dispatcher;
using Microsoft.Practices.Unity;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace Infrastructure.Aspect.Extensions
{
    public class UnityInstanceProvider : IInstanceProvider
    {
       public IUnityContainer Container { set; get; }   
       public Type ServiceType { set; get; }        
       public UnityInstanceProvider() : this(null) {        
       }        
       public UnityInstanceProvider(Type type)        
       {            
           ServiceType = type;                       
       }        
        #region IInstanceProvider Members        
        public object GetInstance(InstanceContext instanceContext, Message message)    
        {            
            return Container.Resolve(ServiceType);        
        }        
        public object GetInstance(InstanceContext instanceContext)        
        {            
            return GetInstance(instanceContext, null);
        }        
        public void ReleaseInstance(InstanceContext instanceContext, object instance)        
        {        

        }        
        #endregion
    }
}
